﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Grishko.DataTier;
using System.Collections;

namespace OutdoorLib.BaseEntity.Dictionary
{
    /// <summary>
    /// Хранилище древовидных справочников (провайдера/агентсва)
    /// </summary>
    public class DictionaryStorage : EntitySingle
    {
        //public class DictionaryKeyList : EntityList
        //{
        //    protected EntityList ObligationKeys { get; set; }

        //    public EntityList GetFullList()
        //    { 
        //        {
        //            return ObligationKeys;
        //        }

        //    }
        //}

        protected EntityList _Dictionary = new EntityList();
        protected EntityList _AddKyes= new EntityList ();

        public DictionaryStorage(): base()
        {
        }
        
        /// <summary>
        /// Справочники TreeDictionaryItem
        /// </summary>
        public EntityList DictionaryList { get { return _Dictionary; } set { _Dictionary = value; } }

        /// <summary>
        /// Полный список возможых типов справочников
        /// </summary>
        public List<DictionaryItem >KeyList
        {
            get
            {
                List<DictionaryItem> res = new List<DictionaryItem>();
                foreach (DictionaryItem i in MyObligationKeys)
                {
                    res.Add(i);
                }

                foreach (DictionaryItem i in AddKyes)
                {
                    res.Add( i);
                }
                return res;
             
            }
            
        }

        /// <summary>
        /// Дополнительные справочники Провайдера / Агентсва
        /// </summary>
        public EntityList AddKyes { get { return _AddKyes; } set { _AddKyes = value; } }

        /// <summary>
        /// Обязательные типы справочников - поддерживаемые агенством/провайдером
        /// </summary>
        protected virtual EntityList MyObligationKeys
        {
            get
            {
                EntityList res = new EntityList();
                return res;
            }
        }


        /// <summary>
        /// Вернуть ключ 
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public   DictionaryItem  GetDictionaryKey (string ID)
        {
            foreach (DictionaryItem i in KeyList)
            {
                if (i.ID.Equals(ID))
                    return i;
            }
            return null;
        }

        /// <summary>
        /// выбрать ключ и создать справочник 
        /// </summary>
        /// <param name="Key"></param>
        public TreeDictionaryItem CreateTreeDictionaryItem(string sKey)
        {
            DictionaryItem Key = (DictionaryItem)GetDictionaryKey(sKey);
            if (null == Key)
                throw new Exception(String.Format("Справочник {0} не найден", sKey));

            TreeDictionaryItem Dictionary = new TreeDictionaryItem()
            {
                TypeID = Key.ParamID,
                Name = Key.Value.ToString()
            };
            return Dictionary;
        }
    }



    public class ProvaiderDictionaryStorage : DictionaryStorage
    {

        //Обязательные типы справочников для провайдера
        protected override EntityList MyObligationKeys
        {
            get
            {
                EntityList res = new EntityList();
                DictionaryItem i = new DictionaryItem() { ID = TreeDictionaryItem.TreeDictionary_ConstractionType, ParamID = TreeDictionaryItem.TreeDictionary_ConstractionType, Value = "Типы конструкций" };
                res.Add(i);
                i = new DictionaryItem() { ID = TreeDictionaryItem.TreeDictionary_AdressProgram, ParamID = TreeDictionaryItem.TreeDictionary_AdressProgram, Value = "Адресные программы" };
                res.Add(i);
                return res;
            }
        }
      
    }

    public class AgencyDictionaryStorage : DictionaryStorage
    {

        protected override EntityList MyObligationKeys
        {
            get
            {
                EntityList _ObligationKeys = new EntityList();
                DictionaryItem d = new DictionaryItem() { ID = TreeDictionaryItem.TreeDictionary_ClientsCategory, ParamID = TreeDictionaryItem.TreeDictionary_ClientsCategory, Value = "Категория клиента" };
                _ObligationKeys.Add(d);

                d = new DictionaryItem() { ID = TreeDictionaryItem.TreeDictionary_ClientStatus, ParamID = TreeDictionaryItem.TreeDictionary_ClientStatus, Value = "Статус клиента" };
                _ObligationKeys.Add(d);

                d = new DictionaryItem() { ID = TreeDictionaryItem.TreeDictionary_ConstractionConditions, ParamID = TreeDictionaryItem.TreeDictionary_ConstractionConditions, Value = "Ограничения конструкции" };
                _ObligationKeys.Add(d);

                d = new DictionaryItem() { ID = TreeDictionaryItem.TreeDictionary_GeoBinding, ParamID = TreeDictionaryItem.TreeDictionary_GeoBinding, Value = "Привязка конструкции" };
                _ObligationKeys.Add(d);

                d = new DictionaryItem() { ID = TreeDictionaryItem.TreeDictionary_LocationDescribe, ParamID = TreeDictionaryItem.TreeDictionary_LocationDescribe, Value = "Транспортная привязка" };
                _ObligationKeys.Add(d);
                return _ObligationKeys;
            }
        }

    }
}
